proc useradd {nick handle chan otbn1 host otbn tcl} {
  global home botnick bcast

  if {$otbn1 == ""} {
    putquick "NOTICE $nick :\0034ERROR - Invalid Syntax - Should Be - (/msg) $botnick useradd <nick> <#channel> <level>"
    return 0
  }

  if {$otbn == ""} {
    putquick "NOTICE $nick :\0034ERROR - Unknown Level - use one of these levels: avoice,aop,op,ccadmin,cadmin,bop,bcadmin,root"
    return 0
  }
 
  if {![onchan $otbn1 $chan]} {
    putquick "NOTICE $nick :\0034ERROR - $otbn1 not found on $chan"
    return 0
  }

  set hostname [getchanhost $otbn1 $chan]

  if {[string match "~*" $hostname]} {
    set hostname [string range $hostname 1 end]
  }

  set dhost [maskhost *$hostname]
  set hand2 [nick2hand $otbn1 $chan]
  set otbn [string tolower $otbn]
  set newuser 0

  if {[string match {voice} $otbn] == 1 } {  
    putquick "NOTICE $nick :\0034Unable To Execute Command - Voice level does not exist.  Try using AVoice instead."
    return 0
  }

  if {[string match {avoice} $otbn] == 1 } {  
    if {![matchattr $handle o|m $chan]} {
      putquick "NOTICE $nick :\0034Unable To Execute Command - Permission Denied."
      return 0
    }
    
    if {[matchattr $otbn1 |+f $chan]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exists in $chan - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1
    }

    putlog "!$nick ($host)! useradd $chan $otbn1 avoice"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd \002$otbn1\002 into my user partition in channel record: '$chan'. Level: AutoVoice."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my user partition by: \002$nick\002"

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\00312Do not set pass until you are told to do so..."
    }

    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Channel\002:\00312 $chan"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 AutoVoice"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost" 

    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :\0033You currently have a password set - type \002/msg $botnick auth <password>\002 to login."
    }

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing\00312 \002/msg $botnick auth <password>\002"
      putquick "NOTICE $otbn1 :\00312You may do so by typing\00312 \002/msg $botnick pass <password>\002 now"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }

    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Channel\002:\00312 $chan"
    putquick "NOTICE $nick :\002Level\002:\00312 AutoVoice"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"		
    #chattr [nick2hand $otbn1 $chan] |+vf $chan
    #chattr [nick2hand $otbn1 $chan] +hp

    #Fix impossible to have access in 2 rooms bug
    chattr $otbn1 |+vf $chan
    chattr $otbn1 +hp
    save
    return 0
  }

  if {[string match {op} $otbn] == 1 } {
    if {![matchattr $handle o|m $chan]} {
      putquick "NOTICE $nick :Unable To Execute Command - Permission Denied."
      return 0
    }

    if {[matchattr $otbn1 |+f $chan]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exsists' in $chan - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1
    }

    putlog "!$nick ($host)! useradd $chan $otbn1 op"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd $otbn1 into my user partition in channel record '$chan'. Level: Channel Operator."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my user partition by: \002$nick\002"
    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Channel\002:\00312 $chan"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 Channel Operator"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost"

    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :You currently have a password set - type \002/msg $botnick auth <password>\002 to login."
    }

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing \002/msg $botnick auth <password>\002"
      putquick "NOTICE $otbn1 :\0034You may do so by typing \002/msg $botnick pass <password>\002"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }

    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Channel\002:\00312 $chan"
    putquick "NOTICE $nick :\002Level\002:\00312 Channel Operator"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"
    #Fix impossible to have access in 2 rooms bug
    #chattr [nick2hand $otbn1 $chan] |+of $chan
    #chattr [nick2hand $otbn1 $chan] +hp
    chattr $otbn1 |+of $chan
    chattr $otbn1 +hp
    save
  }

  if {[string match {ccadmin} $otbn] == 1 } {
    if {![matchattr $handle o|n $chan]} {
      putquick "NOTICE $nick :Unable To Execute Command - Permission Denied."
      return 0
    }

    if {[matchattr $otbn1 |+f $chan]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exists in $chan - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1
    }

    putlog "!$nick ($host)! useradd $chan $otbn1 ccadmin"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd \002$otbn1\002 into my user partition in channel record '$chan'. Level: Channel Co-Administrator."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my user partition by: \002$nick\002"
    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Channel\002:\00312 $chan"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 Channel Co-Administrator"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost" 

    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :\0033You currently have a password set - type \002/msg $botnick auth <password>\002 to login."  
    }
    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing \002/msg $botnick auth <password>\002" 
      putquick "NOTICE $otbn1 :\0034You may do so by typing \002/msg $botnick pass <password>\002"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }
  
    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Channel\002:\00312 $chan"
    putquick "NOTICE $nick :\002Level\002:\00312 Channel Co-Administrator"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"		
    Fix impossible to have access in 2 rooms bug	
    #chattr [nick2hand $otbn1 $chan] |+fmo $chan
    #chattr [nick2hand $otbn1 $chan] +hp
    chattr $otbn1 |+fmo $chan
    chattr $otbn1 +hp
    save
  }

  if {[string match {cadmin} $otbn] == 1 } {
    if {![matchattr $handle o]} {
      putquick "notice $nick :\0034Unable To Execute Command - Permission Denied."
      return 0
    }

    if {[matchattr $otbn1 |+f $chan]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exists in $chan - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1
    }

    putlog "!$nick ($host)! useradd $chan $otbn1 cadmin"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd $otbn1 into my user partition in channel record '$chan'. Level: Channel Administrator."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my user partition by: \002$nick\002"
    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Channel\002:\00312 $chan"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 Channel Administrator"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost"

    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :\0033You currently have a password set - type \002/msg $botnick auth <password>\002 to login."
    }

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing \002/msg $botnick auth <password>\002"
      putquick "NOTICE $otbn1 :\0034You may do so by typing \002/msg $botnick pass <password>\002"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }

    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Channel\002:\00312 $chan"
    putquick "NOTICE $nick :\002Level\002:\00312 Channel Administrator"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"

	#fix bug
    #chattr [nick2hand $otbn1 $chan] |+fmno $chan
    #chattr [nick2hand $otbn1 $chan] +hp
    chattr $otbn1 |+fmno $chan
    chattr $otbn1 +hp
    save
  }

  if {[string match {bop} $otbn] == 1} {
    if {![matchattr $handle m]} { 
      putquick "NOTICE $nick :\0034Unable To Execute Command - Permission Denied."
      return 0
    }

    if {[matchattr $otbn1 +f]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exists - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1
    }

    putlog "!$nick ($host)! useradd $otbn1 bop"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd $otbn1 into my user partition. Level: BotNet Operator."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my user partition by: \002$nick\002"
    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 BotNet Operator"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost"
 
    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :\0033You currently have a password set - type \002/msg $botnick auth <password>\002 to login."  
    }

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing \002/msg $botnick auth <password>\002"
      putquick "NOTICE $otbn1 :\0034You may do so by typing \002/msg $botnick pass <password>\002"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }
  
    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Level\002:\00312 BotNet Operator"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"
  
	#Not need to fix bug here... odd?
    chattr [nick2hand $otbn1 $chan] +ofpxh
    save
  }

  if {[string match {bcadmin} $otbn] == 1 } {
    if {![matchattr $handle n]} {
      putquick "NOTICE $nick :Unable To Execute Command - Permission Denied."
      return 0
    }

    if {[matchattr $otbn1 +f]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exists - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1
    }

    putlog "!$nick ($host)! useradd $otbn1 bcadmin"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd $otbn1 into my user partition. Level: BotNet Co-Administrator."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my user partition by: \002$nick\002"
    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 BotNet Co-Administrator"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost"

    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :\0033You currently have a password set - type \002/msg $botnick auth <password>\002 to login."
    }

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing \002/msg $botnick auth <password>\002"
      putquick "NOTICE $otbn1 :\0034You may do so by typing \002/msg $botnick pass <password>\002"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }

    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Level\002:\00312 BotNet Co-Administrator"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"
	#Bug fix not needed here
    chattr [nick2hand $otbn1 $chan] +fhjmoptx
    save
  }

  if {[string match {root} $otbn] == 1 } {
    if {![matchattr $handle n]} {
      putquick "NOTICE $nick :\0034Unable To Execute Command - Permission Denied."
      return 0
    }

    if {[matchattr $otbn1 +f]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exists - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1
    }

    putlog "!$nick ($host)! useradd $otbn1 root"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd $otbn1 into my root partition. Level: BotNet Administrator."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my root partition by: \002$nick\002"
    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 BotNet Administrator (root)"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost"

    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :\0033You currently have a password set - type \002/msg $botnick auth <password>\002 to login."
    }

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing \002/msg $botnick auth <password>\002"
      putquick "NOTICE $otbn1 :\0034You may do so by typing \002/msg $botnick pass <password>\002"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }

    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Level\002:\00312 BotNet Administrator (root)"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"
	#bug fix not needed here cuz global
    chattr [nick2hand $otbn1 $chan] +fhjmnoptx
    save
  }

  if {[string match {aop} $otbn] == 1 } {
    if {![matchattr $handle o|m $chan]} {
      putquick "NOTICE $nick :\0034Unable To Execute Command - Permission Denied."
      return 0
    }

    if {[matchattr $otbn1 |+f $chan]} {
      putquick "NOTICE $nick :\0034ERROR - Unable to add user - the user $otbn1 currently exists in $chan - try using the usermod command."
      return 0
    }

    if {![validuser $hand2]} {
      adduser $otbn1 $dhost
      set newuser 1 
    }

    putlog "!$nick ($host)! useradd $chan $otbn1 aop"

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to useradd $otbn1 into my user partition in channel record '$chan' Level: AutoOp."
    }

    putquick "NOTICE $otbn1 :\0033You have been added into my user partition by: \002$nick\002"
    putquick "NOTICE $otbn1 :\0033Info Follows...."
    putquick "NOTICE $otbn1 :\002Your ID\002:\00312 $otbn1"
    putquick "NOTICE $otbn1 :\002Channel\002:\00312 $chan"
    putquick "NOTICE $otbn1 :\002Level\002:\00312 AutoOp"
    putquick "NOTICE $otbn1 :\002Host\002:\00312 $dhost"

    if {$newuser == 0} {
      putquick "NOTICE $otbn1 :\0033You currently have a password set - type \002/msg $botnick auth <password>\002 to login."
    }

    if {$newuser == 1} {
      putquick "NOTICE $otbn1 :\0034You \002!MUST!\002 set a password for future identification purposes.You will need this password to log in every time you want to use the bot by typing \002/msg $botnick auth <password>\002"
      putquick "NOTICE $otbn1 :\0034You may do so by typing \002/msg $botnick pass <password>\002"
      putquick "NOTICE $otbn1 :\0034WARNING:\00312 Do not authenticate until you receive a notice that your password has been set"
    }

    putquick "NOTICE $nick :\0033Sucessfully Added:"
    putquick "NOTICE $nick :\002ID\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Nick\002:\00312 $otbn1"
    putquick "NOTICE $nick :\002Channel\002:\00312 $chan"
    putquick "NOTICE $nick :\002Level\002:\00312 AutoOp"
    putquick "NOTICE $nick :\002Host\002:\00312 $dhost"
   # chattr [nick2hand $otbn1 $chan] |+fa $chan #Removed to fix access impossible in 2 rooms bug
    chattr $otbn1 |+fa $chan
    save
  }
}